package daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import dao.BackCommentDao;
import pojo.College;
import pojo.MessageComment;
import utils.DruidUtils;

public class BackCommentDaoImpl implements BackCommentDao{

	@Override
	public ArrayList<MessageComment> getMc() {
		Connection conn = DruidUtils.getConnection();
		String sql = "select * from messagecomment";
		ArrayList<MessageComment> mcList = new ArrayList<MessageComment>();
		try {
			PreparedStatement pre = conn.prepareStatement(sql);
			ResultSet res = pre.executeQuery();
			while(res.next()) {
				MessageComment mc = new MessageComment();
				mc.setMcid(res.getInt("mcid"));
				mc.setMid(res.getInt("mid"));
				mc.setUserid(res.getInt("userid"));
				mc.setMcContent(res.getString("mcContent"));
				mc.setMcTime(res.getDate("mcTime"));
				mc.setMcLoveNum(res.getInt("mcLoveNum"));
				mcList.add(mc);
			}
			res.close();
			pre.close();
			conn.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return mcList;
	}

	@Override
	public int delMc(int mcid) {
		Connection conn = DruidUtils.getConnection();
		String sql = "delete from messagecomment where mcid = ?";
		PreparedStatement pre = null;
		try {
			pre = conn.prepareStatement(sql);
			pre.setInt(1, mcid);
			return pre.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				pre.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return 0;
	}

}
